//
//  MujiDubTools.m
//  testdemo
//
//  Created by yule on 2017/6/2.
//  Copyright © 2017年 yule. All rights reserved.
//

#import "MujiDubTools.h"
#import "AFNetworking.h"
#import "MujiDubHeader.h"

@implementation MujiDubTools

+ (instancetype)share
{
    
    static MujiDubTools *tool = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        
        tool = [[MujiDubTools alloc] init];
    });
    
    return tool;
}

// 监听网络状态
- (void)observeNetReachability
{
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        //        NetworkStatus netStatus  = status;
        switch (status) {
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");
                [[NSUserDefaults standardUserDefaults] setObject:@1 forKey:kReachabilityStatus];
                
                
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"自带网络");
                [[NSUserDefaults standardUserDefaults] setObject:@2 forKey:kReachabilityStatus];
                
                break;
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"没有网络");
                
                [[NSUserDefaults standardUserDefaults] setObject:@0 forKey:kReachabilityStatus];
                
                break;
            case AFNetworkReachabilityStatusUnknown:
                NSLog(@"未知网络");
                break;
            default:
                break;
        }
        
//        [[NSNotificationCenter defaultCenter] postNotificationName:kReachabilityStatusChange
//                                                            object:self];
        
        
        
    }];
}



- (NSDate *)getCurrentTime
{
    NSDate *  senddate=[NSDate date];
    
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    
    [dateformatter setDateFormat:@"YYYY-MM-dd  HH:mm:ss:ss"];
    
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    
    // NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:timeDate];
    return senddate;

}

- (float)dateTimeDifferenceWithStartTime:(NSDate *)startTime endTime:(NSDate *)endtime
{
    
    NSTimeInterval timeInterval = [endtime timeIntervalSinceDate:startTime];
    
    return timeInterval;
}


- (float)dateTimeDifferenceWithStartTime:(NSDate *)startTime
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    
    //[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    //NSDate *timeDate = [dateFormatter dateFromString:startTime];
    
    NSDate *currentDate = [NSDate date];
    
    NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startTime];

    return timeInterval;
}
@end
